package com.zdj.question;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author zdj
 * @date 2023-03-31 11:29
 */
//hide-start
public class CalculateDiscount {

    public static void main(String[] args) {
        Object result = CalculateDiscountSolution.solution(args[0]);
        System.out.print(result);
    }
}
//hide-end

class CalculateDiscountSolution {
    public static Object solution(String a) {
        BigDecimal price = new BigDecimal(a);
        BigDecimal cost = new BigDecimal(0);
        //write your code here......
        //考虑到购买5000元东西的人很少，应从小到大判断，以减少判断次数
        cost = (price.compareTo(new BigDecimal(100)) == -1 ? price : price.compareTo(new BigDecimal(500)) == -1
                ? price.multiply(new BigDecimal(0.9)) : price.compareTo(new BigDecimal(2000)) == -1
                ? price.multiply(new BigDecimal(0.8)) : price.compareTo(new BigDecimal(5000)) == -1
                ? price.multiply(new BigDecimal(0.7)) : price.multiply(new BigDecimal(0.6)));
        return cost.setScale(2, RoundingMode.HALF_UP);
    }
}
